package servlet;

import java.io.IOException;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;






import service.BookService;
import vo.BookBean;

public class booklist extends HttpServlet{
	@SuppressWarnings("static-access")
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		   resp.setContentType("application/json;charset=utf-8");
		   PrintWriter w = resp.getWriter();
		   String b_name=req.getParameter("b_name");
		   String val = req.getParameter("v");
		   System.out.println(b_name);
		   JSONObject j=new JSONObject();
		   BookService list=new BookService();
		   if(val!=null){
			   String aa=val.substring(1,2);
				 int a=Integer.parseInt(aa);
				 List<Object> book =list.getname(b_name,(a-1)*8,8);
				 j.put("ss", book);
		   }else{
		    List<Object> book = list.getname(b_name, 0, 8);
		    j.put("ss", book);}
		    List<String[]> ys = list.getys(b_name);
		    List l=new ArrayList();
		    String s = ys.get(0)[0];
		    int v=Integer.parseInt(s);
		    int b=(v-1)/8+1;
		    for(int i=1;i<=b;i++){
		    	l.add(i);
		    
		    j.put("ys", l);}
		    w.write(j.toString());	
            w.close();
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
